package com.ts_xiaoa.ts_android_library.voice

import android.app.Service
import android.content.Intent
import android.media.MediaRecorder
import android.os.IBinder


/**
 * create by ts_xiaoA on 2020-09-26 10:01
 * email：443502578@qq.com
 * desc：
 */
class VoiceService : Service() {

    //文件保存路径
    private var filePath: String? = null

    //音频录制对象
    private var mediaRecorder: MediaRecorder? = null


    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        return super.onStartCommand(intent, flags, startId)
    }

    override fun onBind(intent: Intent?): IBinder? {
        TODO("Not yet implemented")
    }


    //开始录音
    private fun startRecording() {
        mediaRecorder = MediaRecorder()
        mediaRecorder?.let {
            //设置声源--->MediaRecorder.AudioSource.MIC(麦克风)
            it.setAudioSource(MediaRecorder.AudioSource.MIC)
            //录音文件保存的格式 Android SDK4.1.2（API 16）及以上版本支持播放
            it.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS)
            it.setOutputFile(filePath) // 设置录音文件的保存路径
            it.setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
            it.setAudioChannels(1)
            // 设置录音文件的清晰度
            it.setAudioSamplingRate(44100);
            it.setAudioEncodingBitRate(192000);
        }
    }

    // 设置录音文件的名字和保存路径
    fun setFileNameAndPath() {

    }

}